{extend name="common/base" /}
{block name="body"} 
<div class="Content" id="content">
    <div class="container">
        <div class="cashNav">
            <a class="item " href="/merchant/finance_cash.html">提现</a>
            <a class="item " href="/merchant/finance_log.html">提现记录</a>
            <a class="item active" href="/merchant/finance_account.html">提现账户</a>
        </div>

        <div class="CashPage">
            <div class="content">
                <div class="FormPage">
                    <form class="layui-form " lay-filter="productForm">
                        <div class="form-item-inline">
                            <label class="must form-label">收款人（公司）：</label>
                            <div class="input-inline">
                                <input type="text" name="account_user" value="{$merchant_account.account_user|default=''}" class="layui-input" placeholder="请输入收款人姓名或公司名称"
                                    lay-verify="required">
                                <br>
                                <p class="layui-form-mid layui-word-aux">个人填写姓名，向平台提供发票的服务方，填写对公企业名称</p>
                            </div>
                        </div>

                        <!-- <div class="form-item-inline">
                            <label class=" form-label">收款方式：</label>
                            <div class="input-inline">
                                <select name="account_type" lay-verify="required">
                                    <option value="">请选择收款方式</option>
                                    <option value="1" {if ($merchant_account && $merchant_account.account_type == 1)} selected {/if}>支付宝</option>
                                    <option value="2" {if ($merchant_account && $merchant_account.account_type == 2)} selected {/if}>微信</option>
                                </select>
                            </div>
                        </div> -->
                        <div class="form-item-inline">
                            <label class="must form-label">银行卡号：</label>
                            <div class="input-inline">
                                <input type="text" name="enc_bank_no" value="{$merchant_account.enc_bank_no|default=''}" class="layui-input" placeholder="请输入银行卡号"
                                    lay-verify="required">
                                <br>
                                <p class="layui-form-mid layui-word-aux">请输入正确的银行卡号</p>
                            </div>
                        </div>

                        <div class="form-item-inline">
                            <label class="must form-label">用户名：</label>
                            <div class="input-inline">
                                <input type="text" name="enc_true_name" value="{$merchant_account.enc_true_name|default=''}" class="layui-input" placeholder="请输入用户名"
                                    lay-verify="required">
                                <br>
                                <p class="layui-form-mid layui-word-aux">请输入银行卡号绑定的用户名</p>
                            </div>
                        </div>

                        <div class="form-item-inline">
                            <label class="must form-label">开户行：</label>
                            <div class="input-inline">
                                <select name="bank_code" lay-search>
                                    {volist name="bank_codes" id="bank"} 
                                     <option value="{$bank.bank_code}">{$bank.bank_name}</option>
                                    {/volist}
                                  </select>
                                <br>
                                <p class="layui-form-mid layui-word-aux">请输入银行卡号绑定的用户名</p>
                            </div>
                        </div>
                        <div class="form-item-inline">
                            <label class="must form-label">交易密码：</label>
                            <div class="input-inline">
                                <input type="password" name="password" class="layui-input" placeholder="请输入交易密码"
                                    lay-verify="required|password" id="password">
                                <p class="layui-form-mid layui-word-aux">
                                    本站交易密码
                                    <!-- <a class="red" style="margin-left: 10px;" id="forgetPassword">忘记交易密码？</a> -->
                                </p>
                            </div>
                        </div>

                        <div class="form-item-inline">
                            <label class="must form-label">确认交易密码：</label>
                            <div class="input-inline">
                                <input type="password" name="re_password" class="layui-input" placeholder="请再次输入交易密码"
                                    lay-verify="required|confirmPassword">
                                <p class="layui-form-mid layui-word-aux">
                                    请再次输入交易密码以确保一致</p>
                            </div>
                        </div>

                        <!-- 按钮区域 -->
                        <div class="form-item-inline ">
                            <label class=" form-label"></label>
                            <div class="input-inline foot">
                                <button class="layui-btn" lay-submit="" lay-filter="saveAccount">确认并保存</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

            <div class="tips">
                <b>说明</b>
                <p>1.企业服务方提现需先向平台提供发票后解锁金额(发票开出后,请提交发票已开出提醒,通知平台解锁),发票抬头请见服务费页面底部<br>
                    2.充值金额不能提现，可提现金额来自您的收入。</p>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"} 
<script>
    changeTitleName('提现账号');
    
    layui.use(['form', 'layer', 'jquery'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        
        // 自定义验证规则
        form.verify({
            password: [
                /^[\S]{6,12}$/,
                '密码必须6到12位，且不能出现空格'
            ],
            confirmPassword: function(value) {
                if($('#password').val() !== value) {
                    return '两次输入的密码不一致';
                }
            }
        });
        
        // 忘记密码点击事件
        $('#forgetPassword').on('click', function(){
            layer.open({
                type: 2,
                title: '找回交易密码',
                area: ['500px', '400px'],
                content: '/merchant/reset_transaction_password.html' // 替换为实际找回密码页面
            });
        });
        
        // 表单提交
        form.on('submit(saveAccount)', function(data){
            var loading = layer.load(2); // 显示加载中
            
            $.ajax({
                url: '/merchant/save_finance_account', // 替换为实际提交地址
                type: 'POST',
                dataType: 'json',
                data: data.field,
                success: function(res){
                    layer.close(loading);
                    if(res.code === 200){
                        layer.msg('保存成功', {icon: 1});
                        // 可以添加页面刷新或其他操作
                    }else{
                        layer.msg(res.msg || '保存失败', {icon: 2});
                    }
                },
                error: function(){
                    layer.close(loading);
                    layer.msg('网络错误，请稍后再试', {icon: 2});
                }
            });
            
            return false; // 阻止表单跳转
        });
        
        // 初始化表单值
        form.val("productForm", {
            "account_user": "{$merchant_account.account_user|default=''}",
            "account_type": "{$merchant_account.account_type|default=''}",
            "account": "{$merchant_account.account|default=''}"
        });
    });
</script>
{/block}